class LinkNode<E>{
    E data;
    LinkNode<E> next;
    public LinkNode() {
        this.next = null;
    }
    public LinkNode(E data) {
        this.data = data;
        this.next = null;
    }
}

public class LinkStack<E> {
    LinkNode<E> head;

    public LinkStack() {
        head = new LinkNode<E>();
        head.next = null;
    }

    public boolean empty(){
        return head.next==null;
    }

    public void push(E e){
        LinkNode<E> t = new LinkNode<E>(e);
        t.next = head.next;
        head.next= t;
    }

    public E pop(){
        if(empty()){
            throw new IllegalArgumentException("栈为空");
        }
        E ret = head.next.data;
        head.next = head.next.next;
        return ret;
    }

    public E top(){
        if(empty()){
            throw new IllegalArgumentException("栈为空");
        }
        return head.next.data;
    }
}
